<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数参数默认值</title>
</head>
<script>
    //ES6允许给函数形参赋初始值
    //1、形参初始值 具有默认值的参数,一般位置靠后(潜规则)
    function add(a,b,c=10) {
        return a + b + c
    }
    //c传3就用3,不传的话,用初始值10
    let result = add(1,2,3)
    console.log(result)
    let result2 = add(1,2)
    console.log(result2)
    //2、与解构赋值结合用
    function connect({host='127.0.0.1',username,password,port}) {
        console.log(host,username,password,port)
    }
    connect({
        host: 'localhost',
        username: 'root',
        password: 'root',
        port: 3306
    })
</script>
</html>